package com.example.mvpdemo;

import android.app.Application;
import android.content.Context;

import com.example.mvpdemo.dao.manager.DBManager;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;

public class GlobalApplication extends Application {

    private RefWatcher refWatcher;

    @Override
    public void onCreate() {
        super.onCreate();
        refWatcher = setupLeakCanary();
        //初始化greendao数据库
        DBManager.getInstance().init(this);
    }

    private RefWatcher setupLeakCanary() {
        if (LeakCanary.isInAnalyzerProcess(this)) {
            return RefWatcher.DISABLED;
        }
        return LeakCanary.install(this);
    }

    /***
     * 检查（除Activity）类内存泄漏调用
     * @param context
     * @return
     */
    public static RefWatcher getRefWatcher(Context context) {
        GlobalApplication leakApplication = (GlobalApplication) context.getApplicationContext();
        return leakApplication.refWatcher;
    }
}
